#include <filesystem>

namespace hms
{
namespace fs = std::filesystem;

template<typename Format>
bool decideImport(
	const ImportSettings::ImportItem<Format>& item,
	const fs::path& otherFile,
	bool otherIsDummy
){
	auto checkFile = [&](){
		if ( !fs::is_regular_file(item.file) )
			throw FileError( fmt::format(
				"{}:\n{}\"{}\"",
				bold( red("Import file not found") ),
				indent(),
				bold( item.file.string() )
				// "Import file \"" + item.file.string() + "\" not found!"
			) );
	};
	switch(item.import){
		using Flag = ImportSettings::Flag;
		case Flag::never:
			return false;
		case Flag::always:
			return true;
		case Flag::ifNotFound:
			return !fs::is_regular_file(otherFile) || otherIsDummy;
		case Flag::ifNewer:
			checkFile();
			return ( fs::is_regular_file(otherFile) && !otherIsDummy ) ?
				fs::last_write_time(item.file) >
				fs::last_write_time(otherFile) :
				true;
		default:
			std::cout
				<< "Flag value: " << magic_enum::enum_name(item.import)
				<< "\nFile path: " << item.file
				<< "\nOther file path: " << otherFile
				<< "\nOther is dummy: " << std::boolalpha << otherIsDummy
				<< '\n';
			UNREACHABLE;
	}
}

} // namespace hms
